import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/club_ranking/club_ranking_controller.dart';
import 'package:flutter_changdian_football/pages/mine/user_store.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/pull/pull_smart_refresher.dart';
import 'package:flutter_changdian_football/widget/course/club_ranking_item.dart';
import 'package:flutter_changdian_football/widget/input/search_input_widget.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:get/route_manager.dart';

/// 俱乐部排行
class ClubRankingPage extends StatelessWidget {
  const ClubRankingPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF8FAF9),
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: const Color(0xffF8FAF9),
        elevation: 0,
        title: Text(
          '俱乐部排行',
          style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333)),
        ),
        iconTheme: const IconThemeData(
          color: Color(0xff333333)
        ),
      ),
      body: GetBuilder<ClubRankingController>(
        init: ClubRankingController(),
        builder: (clubRankingController) {
          return Column(
            children: [
              SizedBox(height: 10.w,),

              SearchInputWidget(
                hintText: '请输入关键词',
                controller: clubRankingController.searchController,
                onSubmitted: () {
                  EasyLoading.show();
                  clubRankingController.requestData(clubRankingController.controller!);
                },
                isShowClose: clubRankingController.searchController.text != '' ? true : false,
                onChange: () {
                  clubRankingController.update();
                },
                onClose: () {
                  clubRankingController.searchController.clear();
                  clubRankingController.update();
                  EasyLoading.show();
                  clubRankingController.requestData(clubRankingController.controller!);
                },
              ),

              SizedBox(height: 20.w,),

              Container(
                padding: EdgeInsets.symmetric(horizontal: 17.w),
                child: Row(
                  children: [
                    GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        if (clubRankingController.orderType == 'ACTIVITY') {
                          return;
                        }
                        EasyLoading.show();
                        clubRankingController.orderType = 'ACTIVITY';
                        clubRankingController.update();
                        clubRankingController.requestData(clubRankingController.controller!);
                      },
                      child: Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(4.r),
                          color: clubRankingController.orderType == 'ACTIVITY' ? const Color(0xff499360 ).withOpacity(0.06) : Colors.white
                        ),
                        padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 10.w),
                        child: Text('按活跃度', style: TextStyle(fontSize: 14.sp, color: clubRankingController.orderType == 'ACTIVITY' ? const Color(0xff499360) : const Color(0xffcccccc)),),
                      ),
                    ),
                    SizedBox(width: 28.w,),
                    GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        if (clubRankingController.orderType == 'PLAYER_NUM') {
                          return;
                        }
                        EasyLoading.show();
                        clubRankingController.orderType = 'PLAYER_NUM';
                        clubRankingController.update();
                        clubRankingController.requestData(clubRankingController.controller!);
                      },
                      child: Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(4.r),
                          color: clubRankingController.orderType == 'PLAYER_NUM' ? const Color(0xff499360 ).withOpacity(0.06) : Colors.white
                        ),
                        padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 10.w),
                        child: Text('按俱乐部人数', style: TextStyle(fontSize: 14.sp, color: clubRankingController.orderType == 'PLAYER_NUM' ? const Color(0xff499360) : const Color(0xffcccccc)),),
                      ),
                    ),
                  ],
                ),
              ),

              SizedBox(height: 4.w,),

              Expanded(
                child: RefreshWidget<ClubRankingController>(
                  child: ListView.separated(
                    itemCount: clubRankingController.clubRankList.length,
                    physics: const BouncingScrollPhysics(),
                    padding: EdgeInsets.only(left: 17.w, right: 17.w, bottom: 10.w),
                    separatorBuilder: (context, index) {
                      return Container(
                        height: 0.5.w,
                        width: double.infinity,
                        color: const Color(0xffF0F0F0),
                      );
                    },
                    itemBuilder: (BuildContext context, int index) {
                      return ClubRankingItem(
                        index: index,
                        rankingWidget: index < 3 ? SizedBox(
                          width: 22.w,
                          height: 22.w,
                          child: Image.asset('assets/images/icon_no${index+1}.png', fit: BoxFit.fill,),
                        ) : index > 9 ? Container() : Container(
                          width: 22.w,
                          height: 22.w,
                          decoration: BoxDecoration(
                            color: const Color(0xff499360),
                            borderRadius: BorderRadius.circular(22.r)
                          ),
                          alignment: Alignment.center,
                          child: Text('${index + 1}', style: TextStyle(fontSize: 12.sp, color: Colors.white),),
                        ),
                        onTap: () {
                          if (UserStore.to.checkLoginPage()) {
                            Get.toNamed(AppRoutes.clubRankingDetails, parameters: {
                              'clubId': '${clubRankingController.clubRankList[index].clubId ?? ''}'
                            });
                          }
                        }
                      );
                    },
                  ),
                ),
              )
            ],
          );
        }
      ),
    );
  }
}